﻿
@{
    Layout = null;
}

<div class="panel panel-default" ng-controller="OrderManageController" ng-class="{ 'whirl standard': isLoading }">
    <div class="panel-heading">
        <div class="form-inline ng-pristine ng-valid">
            <div class="form-group">
                <input placeholder="订单号" class="form-control" type="text" ng-model="Keywords">
                <select class="form-control" ng-model="ReturnStatus">
                    <option value="-1">处理状态</option>
                    <option value="0">待处理</option>
                    <option value="1">客服处理中</option>
                    <option value="2">已完成</option>
                    <option value="3">已退款</option>
                    <option value="4">已换货</option>
                </select>
                <select class="form-control" ng-model="ReturnType">
                    <option value="-1">退货类型</option>
                    <option value="0">退货</option>
                    <option value="1">换货</option>
                </select>
                <p class="input-group" style="margin-top:10px">
                    <input placeholder="开始时间" datetime-picker="yyyy-MM-dd HH:mm:ss" is-open="picker1.open" datepicker-options="datepickerOptions" class="form-control" type="text" ng-model="BeginTime">
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-default" ng-click="openCalendar($event, 'picker1')"><i class="fa fa-calendar"></i></button>
                    </span>
                </p>
                <p class="input-group" style="margin-top:10px">
                    <input placeholder="结束时间" datetime-picker="yyyy-MM-dd HH:mm:ss" is-open="picker2.open" datepicker-options="datepickerOptions" class="form-control" type="text" ng-model="EndTime">
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-default" ng-click="openCalendar($event, 'picker2')"><i class="fa fa-calendar"></i></button>
                    </span>
                </p>
                <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()">
                    <span class="btn-label">
                        <em class="fa fa-search"></em>
                    </span>搜索
                </button>
            </div>
            <div class="form-group">
                <button type="button" class="btn btn-labeled btn-success" ng-click="godt()">
                    <span class="btn-label">
                        <em class="fa fa-plus"></em>
                    </span>导出报表
                </button>
            </div>
        </div>
    </div>
    <div class="panel-body">
        <div class="table-responsive">
            <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                <tbody>
                    <tr ng-repeat="agentInfoManage in $data">
                        <td data-title="'退货单号'" class="text-center">{{agentInfoManage.ReturnNo}}</td>
                        <td data-title="'订单号'" class="text-center">{{agentInfoManage.OrderNo}}</td>
                        <td data-title="'商品'" style="width:20%" class="text-center">{{agentInfoManage.orderDetail.ProductName}}</td>
                        <td data-title="'类型'" class="text-center">{{agentInfoManage.ReturnType==0?'退货':'换货'}}</td>
                        <td data-title="'申请日期'" class="text-center">{{agentInfoManage.AddTime}}</td>
                        <td data-title="'状态'" class="text-center">{{agentInfoManage.SatusDes}}</td>
                        <td data-title="''" nowrap="nowrap" class="text-center">
                            <button type="button" ng-click="edit(agentInfoManage.Id)" class="btn btn-sm btn-info" title="查看">
                                <em class="fa fa-eye"></em>
                            </button>
                            <button type="button" ng-click="del(agentInfoManage.Id)" class="btn btn-sm btn-danger" title="删除">
                                <em class="fa fa-trash-o"></em>
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>


    <script>

        App.controller('OrderManageController', [
        '$scope', '$resource', '$state', '$route', '$http', 'ngTableParams', 'ngTableDataService', 'Notify', '$rootScope',
        function ($scope, $resource, $state, $route, $http, ngTableParams, ngTableDataService, Notify, $rootScope) {
            'use strict';
            $scope.isLoading = true;
            $scope.ReturnStatus = -1;
            $scope.ReturnType = -1;

            // 日期插件
            $scope.picker1 = {
                date: new Date()
            };

            $scope.picker2 = {
                date: new Date()
            };

            $scope.datepickerOptions = {
                showWeeks: false,
                startingDay: 1,
                dateDisabled: function (data) {
                    //return (data.mode === 'day' && (new Date().toDateString() == data.date.toDateString()));
                }
            }

            $scope.openCalendar = function (e, picker) {
                $scope[picker].open = true;
            };



            $scope.tableParams = new ngTableParams({
                page: 1,
                count: 10,
                sorting: {
                    Id: 'desc'     // 初始化排序
                }
            }, {
                getData: function ($defer, params) {
                    $scope.isLoading = true;
                    var requestParams = {
                        Skip: (params.page() - 1) * params.count(),
                        Take: params.count(),
                        Keywords: $scope.Keywords,
                        ReturnStatus: $scope.ReturnStatus,
                        ReturnType: $scope.ReturnType,
                        BeginTime: $scope.BeginTime,
                        EndTime: $scope.EndTime
                    };
                    $http.post('/Order/GetReturnGoodsList', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                        .success(function (data, status) {
                            params.total(data.Total);
                            $defer.resolve(data.Results);

                            $scope.isLoading = false;
                        });
                }
            });

            //跳转更新页面
            $scope.edit = function (id) {
                $state.go('app.returnGoodsInfo', { "id": id });
            }

            $scope.del = function (id) {
                layer.confirm('确定删除吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    layer.closeAll('dialog');
                    $http.post("/Order/DelOrder", { id: id }).then(function (response) {

                        if (response.data.isSuccess) {
                            $scope.tableParams.$params.page = 1;
                            $scope.isLoading = true;
                            $scope.tableParams.reload();
                            $scope.isLoading = false;
                        }
                        else {
                            layer.msg(response.data.msg);
                        }

                    });
                }, function () {

                });
            }

            $scope.godt = function () {
                var t1 = "";
                var t2 = "";
                if ($scope.BeginTime != undefined && $scope.EndTime != undefined) {
                    var begintime = new Date($scope.BeginTime);
                    var endtime = new Date($scope.EndTime);

                    t1 = begintime.getFullYear() + "/" + (begintime.getMonth() + 1) + "/" + begintime.getDate() + " " + begintime.getHours() + ":" + begintime.getMinutes() + ":00";
                    t2 = endtime.getFullYear() + "/" + (endtime.getMonth() + 1) + "/" + endtime.getDate() + " " + endtime.getHours() + ":" + endtime.getMinutes() + ":00";
                }
                location.href = "/Report/GetRerurnGoods?orderno=" + $scope.Keywords + "&begintime=" + t1 + "&endtime=" + t2 + "&satus=" + $scope.ReturnStatus + "&returntype=" + $scope.ReturnType;
            }

        }
        ]);
    </script>

</div>
